/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-05-04 23:14:25
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2025-07-29 16:47:05
 * @FilePath: /yyshort/lib/pages/category/controller.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:yyshort/common/apis/apis.dart';
import 'package:yyshort/common/model/index.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'index.dart';

class CategoryController extends GetxController {
  CategoryController();

  /// UI 组件
  final RefreshController refreshController = RefreshController(
    initialRefresh: true,
  );

  /// 响应式成员变量
  final state = CategoryState();

  /// 成员变量
  String categoryCode = '';
  int curPage = 1;
  int pageSize = 20;
  int total = 20;

  /// 事件

  void onRefresh() {
    // fetchNewsList(isRefresh: true)
    //     .then((_) {
    //       refreshController.refreshCompleted(resetFooterState: true);
    //     })
    //     .catchError((_) {
    //       refreshController.refreshFailed();
    //     });
  }

  void onLoading() {
    // if (state.newsList.length < total) {
    //   fetchNewsList()
    //       .then((_) {
    //         refreshController.loadComplete();
    //       })
    //       .catchError((_) {
    //         refreshController.loadFailed();
    //       });
    // } else {
    //   refreshController.loadNoData();
    // }
  }

  // 方法

  // 拉取数据
  Future<void> fetchNewsList({bool isRefresh = false}) async {
    // var result = await NewsAPI.newsPageList(
    //   params: NewsPageListRequestEntity(
    //     categoryCode: categoryCode,
    //     pageNum: curPage + 1,
    //     pageSize: pageSize,
    //   ),
    // );

    // if (isRefresh == true) {
    //   curPage = 1;
    //   total = result.counts!;
    //   state.newsList.clear();
    // } else {
    //   curPage++;
    // }

    // state.newsList.addAll(result.items!);
  }

  /// 生命周期

  ///dispose 释放内存
  @override
  void dispose() {
    super.dispose();
    // dispose 释放对象
    refreshController.dispose();
  }
}
